﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows;
using System.Globalization;
using CCF20Model;
namespace CCF20
{
    [ValueConversion(typeof(bool), typeof(Visibility))]
    public class TransferedCustomerConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if ((bool)value)
            {
                return Visibility.Visible;
            }
            else
            {
                return Visibility.Hidden;
            }

        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    [ValueConversion(typeof(string), typeof(bool))]
    public class IsEnabledConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string permission = (string)value;
            string buttonName = (string)parameter;
            if (permission.Contains(buttonName))
            {
                return true;
            }
            else
            {
                return false;
            }

        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    [ValueConversion(typeof(Device), typeof(string))]
    public class MaintenanceStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Device device = value as Device;
            if ((device != null)&&(device.DeviceStatus != null) && (device.DeviceStatus == "售出"))
            {
                return string.Format("车辆维护项目初始化: 客户名:{0} \t  车牌: {1} \t IDC号: {2}",
                        device.Customer.Name,
                        device.Customer.Vehicles.FirstOrDefault().VehicleLicense, device.IDCSimNumber);
            }else
            {
                return null;
            }
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
    [ValueConversion(typeof(bool), typeof(string))]
    public class BoolToStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            
            if (parameter == null)
            {
                if ((bool)value)
                {
                    return (string)"是";
                }
                else
                {
                    return (string)"否";
                }
            }
            else
            {
                if ((bool)value)
                {
                    return (string)parameter;
                }
                else
                {
                    switch ((string)parameter)
                    {
                        case "等待":
                            return "已确认";
                        default: 
                            return (string)"否";
                    }
                    
                }
                
            }
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if  (((string)value).Equals("是"))
                return true;
            else
                return false;
        }
    }
}
